/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openmrs.module.basicmodule.DSS.Interpreter;

import org.openmrs.module.basicmodule.DSS.ast.AST;
import org.openmrs.module.basicmodule.DSS.ast.OpTree;


/**
 *
 * @author Stephen
 */
public class Operator {
    private AST t;
    private InterpreterVisitor iv;
    
    public Operator(AST t, InterpreterVisitor iv) {
        this.t = t;
        this.iv = iv;
    }
    public Object execute() {
        String operator = ((OpTree) t).getSymbol().toString();
        if (operator.equalsIgnoreCase("+")) {
            return new AdditionOperator(t, iv).execute();
        } else if (operator.equalsIgnoreCase("-")) {
            return new SubtractionOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("*")) {
            return new MultiplicationOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("/")) {
            return new DivisionOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("==")) {
            return new EqualsOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("!=")) {
            return new NotEqualsOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("<")) {
            return new LessThanOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("<=")) {
            return new LessThanOrEqualOperator(t,iv).execute();
        } else if (operator.equalsIgnoreCase("**")) {
            return new ExponentOperator(t,iv).execute();
        }
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
